package cn.oowoo.sentinelclusterclient.controller;

import cn.oowoo.sentinelclusterclient.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {
    @Autowired
    private TestService testService;

    @RequestMapping("/sentinel/sentinelAloneTest")
    public String sentinelAloneTest(){
        return testService.sentinelAloneTest();
    }


    static class Test{
        // 注意这里的port为我们应用服务器的启动port，对应应用启动参server.port
        public static final String requestPath = "http://localhost:7010/sentinel/sentinelAloneTest";
        public static final String requestPath2 = "http://localhost:7020/sentinel/sentinelAloneTest";
        public static final String requestPath3 = "http://localhost:7030/sentinel/sentinelAloneTest";

        private static RestTemplate restTemplate = new RestTemplate();
        private static RestTemplate restTemplate2 = new RestTemplate();
        private static RestTemplate restTemplate3 = new RestTemplate();

        public static void main(String[] args) {
            while (true) {
                executeGet();
            }
        }

        // 连续执行get请求
        private static void executeGet() {
            restTemplate.getForEntity(requestPath, String.class);
            restTemplate2.getForEntity(requestPath2, String.class);
            restTemplate3.getForEntity(requestPath3, String.class);
        }

    }
}
